<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='https://cdn.staticfile.org/react/16.4.0/umd/react.development.js'></script>
    <script src='https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js'></script>
    <!-- 生产环境中不建议使用 -->
    <script src='https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js'></script>
<!-- PropTypes文件 -->
<script src='https://unpkg.com/prop-types@15.6.2/prop-types.js'></script>
</head>

<body>
    <div id='app'>
    </div>
    <script type='text/babel'>
        /*
            ref的作用是获取真实DOM元素节点。本节先来讲一讲字符串形式的ref使用。其实很简单，就是在虚拟DOM中对于你未来想要拿到其真实DOM的节点加上一个ref属性，值可以自定义，未来react就会在渲染时将所有带有ref属性的虚拟DOM节点转化出来的真实DOM节点一起保存在组件实例对象的refs属性中。读取的方式也很简单，直接this.refs.xxx(xxx就是你给虚拟DOM节点添加的ref="xxx")就可以了.    
        */
        class Demo extends React.Component{

            showInput1 = ()=>{
                console.log(this.refs.input1.value)
            }

            showInput2 = ()=>{
                console.log(this.refs.input2.value)
            }

            render(){
                return (
                    <div>
                        <input type="text" ref='input1'/>
                        <button onClick={this.showInput1}>点我提示左侧输入框信息</button>
                        <input type="text" ref='input2' onBlur={this.showInput2}/>
                    </div>
                )
            }
        }

        ReactDOM.render(<Demo/>,document.getElementById('app'))
    </script>
</body>

</html>